package com.base.service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.hibernate.type.StringType;
import org.hibernate.type.Type;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import tool.ClientTool;
import tool.JsonTool;
import tool.TimeTool;

import com.base.bean.*;
import com.base.dao.*;
import com.base.domain.*;


/**
 * 待完成功能： getDetailByCid() getList(int con,int page,int isDesc)
 * con可以是：1/2/3/4/5的形式 单选按钮的值
 * 
 * @author Administrator
 * 
 */

public class DakaService {

	// 单例模式 start
	private volatile static DakaService instance = null;
	private UserDakaDao dkDao;
	private AddressService addService;
	
	
	private DakaService() {
		dkDao = (UserDakaDao) _BaseDao.ac.getBean("UserDakaDao");
		addService=AddressService.getInstance();
	}
	public static DakaService getInstance() {
		if (instance == null) {
			synchronized (DakaService.class) {// 1
				if (instance == null) {// 2
					instance = new DakaService();// 3
				}
			}
		}
		return instance;
	}
	// 单例模式 end
	public UserDakaDao getDkDao() {
		return dkDao;
	}

	
	
	//签到
	public UserDaka sign(Integer creator,String longitude,String latitude,String mediaId){
	try{
		UserDaka userDaka=new UserDaka();
//		Image image=ImageService.getInstance().upload(creator, mediaId, longitude, latitude);
		
		Image image= ImageService.getInstance().saveImageInfo(creator, mediaId, longitude, latitude,1);
		
//		String addName=addService.getNameByGps(longitude, latitude);
//		System.out.println(addName);
		
		userDaka.setAddName(image.getDiscription());
		userDaka.setPath(image.getPath());
		userDaka.setUid(creator);
		userDaka.setLatitude(latitude);
		userDaka.setLongitude(longitude);
		userDaka.setCreated(TimeTool.getCurrentTime());
		userDaka.setPhotoName(image.getFileName());
		
		userDaka.setState(image.getState());	// 3：重复
		if(image.getState()!=3){
			dkDao.merge(userDaka);
		}
		return userDaka;
	}catch(Exception e){
		e.printStackTrace();
		return null;
	}
	}
	
	public static void main(String[] args){
		DakaService.getInstance().sign(1, "106.6222", "31.79136","mediaId2");
	}

}
